package cn.edu.buaa.nlsde.grid.DatabaseManage;

import java.sql.*;

import cn.edu.buaa.nlsde.grid.DatabaseConnect.*;

public class NodeAlterManage
{
	DBConn db=null;
	Statement stat=null;
	
	public NodeAlterManage(DBConn db)
	{
		this.db=db;
	}
	
	public ResultSet getData(int ClusterID)
	{
		String sql="select * from NodeAlter where ClusterID="+ClusterID+" order by HostID asc";
		try
		{
			stat=db.connect();
			ResultSet rs=stat.executeQuery(sql);
			return rs;
		}
		catch (Exception e)
		{
			return null;
		}
	}
	
	public String addRecord(int ClusterID,int HostID,String status)
	{
		String sql="insert into NodeAlter (ClusterID,HostID,HostStatus) values ("+ClusterID+","+HostID+",'"+status+"')";
		try
		{
			stat=db.connect();
			stat.executeUpdate(sql);
			return "Sucess";
		}
		catch (Exception e)
		{
			return "Fail";
		}
	}
	
	public String deleteRecord(int HostID)
	{
		String sql="delete from NodeAlter where HostID="+HostID;
		try
		{
			stat=db.connect();
			stat.executeUpdate(sql);
			return "Sucess";
		}
		catch (Exception e)
		{
			return "Fail";
		}
	}
	
	public void close() throws SQLException
	{
		db.close();
	}
}
